{$CLEO .qa}
{$USE CLEO+}
{$USE Audio}
{$USE newOpcodes}
{$USE ini}

0000: NOP

script_name "HUNTQA"

// By ArtemQa146

const
    hunt_man = 31@
    animal = 30@
    render_m = 25@
    render_model = 26@
    progress = 28@
    coords_x = 24@
    coords_y = 23@
    coords_z = 22@
    angle_1 = 21@
    left = 1
    right = 2
end

0087: coords_x = 0@ // (float)
0087: coords_y = 1@ // (float)
0087: coords_z = 2@ // (float)
0085: render_model = 3@ // (int)

if
    0E4D: random_percent 4@
then
else
    repeat
    wait 0
    until not locate_char_distance_to_coordinates $PLAYER_ACTOR pos coords_x coords_y coords_z radius 150.0
    0A93: terminate_this_custom_script
end


        repeat
        wait 0
        04ED: load_animation  "PedEventsMod"
        until 04EE:   animation "PedEventsMod" loaded


        if 0E4D: random_percent 50
        then 0@ = 161
        else 0@ = 158
        end
        model.Load(0@)
        model.Load(3065)
        model.Load(357)
        if
            not model.Available(0@)
        then
            repeat
            wait 0
            model.Load(0@)
            until model.Available(0@)
        end
        if
            not model.Available(3065)
        then
            repeat
            wait 0
            model.Load(3065)
            until model.Available(3065)
        end
        if
            not model.Available(357)
        then
            repeat
            wait 0
            model.Load(357)
            until model.Available(357)
        end
        038B: load_requested_models

        009A: hunt_man = create_actor_pedtype 21 model 0@ at coords_x coords_y coords_z
        0173: set_actor hunt_man Z_angle_to 0.0
        0E24: fix_char hunt_man ground 1 brightness 1 and_fade_in 0
        01B2: give_actor hunt_man weapon 33 ammo 100 // Load the weapon model before using this

        0E01: create_object_no_save 3065 at 0.0 0.0 0.0 offset 0 ground 0 to animal
        08D2: object animal scale_model 0.0
        0F04: create_render_object_to_object_from_special animal special_model render_model offset 0 0 0 rotation 0 0 0 store_to render_m
        0E31: set_render_object_visible render_m 0
        0382: set_object animal collision_detection 0
        07F7: set_object animal destructible 0
        0E37: set_render_object_scale render_m 1.5 1.5 1.5
        
        


        model.Destroy(0@)
        model.Destroy(3065)
        model.Destroy(357)

        progress = 0
        
        gosub @go_away

        timera = 0
        progress = 0
        
        repeat
        wait 0
        if and
            056D:   actor hunt_man defined
            03CA:   object animal exists
        then

            0E40: get_current_hour 1@
            if or
                1@ >= 18
                1@ < 6
                0118:   actor hunt_man dead
                not locate_char_distance_to_char $player_actor char hunt_man radius 150.0
                not $ACTIVE_INTERIOR == 0
            then
                break
            end
            
            080E: get_actor hunt_man ped_event_to 1@
            if
                051A:   actor hunt_man damaged_by_actor $PLAYER_ACTOR
            then
                01C2: remove_references_to_actor hunt_man // Like turning an actor into a random pedestrian
                if 056D:   actor hunt_man defined
                then 05E2: AS_actor hunt_man kill_actor $PLAYER_ACTOR
                end
                break
            end
            
            if
                0457:   player $PLAYER_CHAR aiming_at_actor hunt_man
            then
                0E83: get_current_char_weaponinfo $PLAYER_ACTOR store_to 1@
                0E89: get_weaponinfo_fire_type 1@ store_to 2@ //     
                if or
                    2@ == 1 //  
                    2@ == 3 //   (  ..)
                then
                    01C2: remove_references_to_actor hunt_man // Like turning an actor into a random pedestrian
                    if 056D:   actor hunt_man defined
                    then 05E2: AS_actor hunt_man kill_actor $PLAYER_ACTOR
                    end
                    break
                end
            end
            
            if and
                progress == 0
                timera > 15000
            then
                0209: 1@ = random_int_in_ranges 1 4
                if
                    1@ == 1
                then
                    gosub @Aim
                else
                    if
                        1@ == 2
                    then
                        gosub @Shoot_fail
                    else
                        gosub @Shoot_good
                    end
                end
                timera = 0
                continue
            end
            
            if
                progress == 1
            then
                if
                    0611:   actor hunt_man performing_animation "Repair_tire"
                then
                    0613: 1@ = actor hunt_man animation "Repair_tire" time
                    if
                        1@ > 0.9
                    then
                        progress = 0
                        timera = 0
                        0E31: set_render_object_visible render_m 0
                        gosub @go_away
                    end
                end
                if and
                    progress == 1
                    timerb > 3000
                    timerb < 6000
                then
                    0E31: set_render_object_visible render_m 1
                end
            end
            
            if and
                progress == 1
                timerb > 30000
            then
                progress = 0
                timera = 0
                0E31: set_render_object_visible render_m 0
                gosub @go_away
            end
            

        else
            break
        end
        until not player.Defined(0)
            if 056D:   actor hunt_man defined
            then 01C2: remove_references_to_actor hunt_man // Like turning an actor into a random pedestrian
            end
            if 03CA:   object animal exists
            then 01C4: remove_references_to_object animal // This object will now disappear when the player looks away
            end
        04EF: release_animation "PedEventsMod"

        repeat
        wait 0
        until not locate_char_distance_to_coordinates $PLAYER_ACTOR pos coords_x coords_y coords_z radius 100.0

0A93: terminate_this_custom_script


:Aim
0208: 1@ = random_float_in_ranges 20.0 50.0
0208: 2@ = random_float_in_ranges 20.0 50.0
0209: 3@ = random_int_in_ranges 1 3
if 3@ == 1
then 1@ *= -1.0
end
if 3@ == 1
then 1@ *= -1.0
end
0209: 3@ = random_int_in_ranges 1 3
if 3@ == 1
then 2@ *= -1.0
end
if 3@ == 1
then 2@ *= -1.0
end
04C4: store_coords_to 5@ 6@ 7@ from_actor hunt_man with_offset 1@ 2@ 100.0
02CE: 7@ = ground_z_at 5@ 6@ 7@


0208: 1@ = random_float_in_ranges -5.0 5.0
0208: 2@ = random_float_in_ranges 1.0 20.0
0209: 8@ = random_int_in_ranges 3000 6000
04C4: store_coords_to 1@ 2@ 3@ from_actor hunt_man with_offset 1@ 2@ 5.0
0615: define_AS_pack_begin 4@
0667: AS_actor -1 aim_at 1@ 2@ 3@ 8@ ms
06A9: AS_actor -1 look_at_point 5@ 6@ 1000.0 10000 ms
07CD: AS_actor -1 walk_to 5@ 6@ 7@ stop_with_angle 0.0 within_radius 2.0
0616: define_AS_pack_end 4@
0618: assign_actor hunt_man to_AS_pack 4@
061B: remove_references_to_AS_pack 4@
return


:Shoot_fail
0208: 1@ = random_float_in_ranges 20.0 50.0
0208: 2@ = random_float_in_ranges 20.0 50.0
0209: 3@ = random_int_in_ranges 1 3
if 3@ == 1
then 1@ *= -1.0
end
if 3@ == 1
then 1@ *= -1.0
end
0209: 3@ = random_int_in_ranges 1 3
if 3@ == 1
then 2@ *= -1.0
end
if 3@ == 1
then 2@ *= -1.0
end
04C4: store_coords_to 5@ 6@ 7@ from_actor hunt_man with_offset 1@ 2@ 100.0
02CE: 7@ = ground_z_at 5@ 6@ 7@


0208: 1@ = random_float_in_ranges -5.0 5.0
0208: 2@ = random_float_in_ranges 20.0 30.0
04C4: store_coords_to 1@ 2@ 3@ from_actor hunt_man with_offset 1@ 2@ 30.0
0615: define_AS_pack_begin 4@
0668: AS_actor -1 rotate_and_shoot_at 1@ 2@ 3@ 2500 ms
06A9: AS_actor -1 look_at_point 1@ 2@ 1000.0 10000 ms
07CD: AS_actor -1 walk_to 5@ 6@ 7@ stop_with_angle 0.0 within_radius 2.0
0616: define_AS_pack_end 4@
0618: assign_actor hunt_man to_AS_pack 4@
061B: remove_references_to_AS_pack 4@
return


:Shoot_good
0208: 5@ = random_float_in_ranges -5.0 5.0
0208: 6@ = random_float_in_ranges 20.0 30.0
0087: 9@ = 6@ // (float)
0087: 8@ = 5@ // (float)
9@ += 0.5
04C4: store_coords_to 1@ 2@ 3@ from_actor hunt_man with_offset 5@ 6@ 30.0
04C4: store_coords_to 5@ 6@ 7@ from_actor hunt_man with_offset 5@ 6@ 100.0
02CE: 7@ = ground_z_at 5@ 6@ 7@
0615: define_AS_pack_begin 4@
0668: AS_actor -1 rotate_and_shoot_at 1@ 2@ 3@ 2500 ms
05D3: AS_actor -1 goto_point 5@ 6@ 7@ mode 6 time 15000 ms // versionA
0812: AS_actor -1 perform_animation "Repair_tire" IFP "PedEventsMod" framedelta 2.0 loopA 0 lockX 1 lockY 1 lockF 0 time -1  // versionB
0616: define_AS_pack_end 4@
0618: assign_actor hunt_man to_AS_pack 4@
061B: remove_references_to_AS_pack 4@
04C4: store_coords_to 5@ 6@ 7@ from_actor hunt_man with_offset 8@ 9@ 100.0
02CE: 7@ = ground_z_at 5@ 6@ 7@
01BC: put_object animal at 5@ 6@ 7@
progress = 1
timerb = 0
return

:go_away
0208: 1@ = random_float_in_ranges 20.0 50.0
0208: 2@ = random_float_in_ranges 20.0 50.0
0209: 3@ = random_int_in_ranges 1 3
if 3@ == 1
then 1@ *= -1.0
end
0209: 3@ = random_int_in_ranges 1 3
if 3@ == 1
then 2@ *= -1.0
end
04C4: store_coords_to 1@ 2@ 3@ from_actor hunt_man with_offset 1@ 2@ 100.0
02CE: 3@ = ground_z_at 1@ 2@ 3@
07CD: AS_actor hunt_man walk_to 1@ 2@ 3@ stop_with_angle 270.0 within_radius 2.0
return
